package com.cqc.supportlibary01;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

/**
 * Created by ${cqc} on 2017/1/20.
 */

public class BottomSheetDialogFragment1 extends BottomSheetDialogFragment {

    private BottomSheetBehavior<View> behavior;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
//      BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

//        dialog.setContentView(R.layout.dialog_bottom_sheet);
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_bottom_sheet, null);

        dialog.setContentView(view);
        behavior = BottomSheetBehavior.from((View) view.getParent());

        Button btnExit = (Button) view.findViewById(R.id.btn_confirm2);
        btnExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return dialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);//默认展开STATE_COLLAPSED
    }

//    @Nullable
//    @Override
//    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        View rootView = inflater.inflate(R.layout.dialog_frag_2, container, false);
//        return rootView;
//    }
}
